using System;
using System.Web;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;




namespace MeuSite
{
	public partial class Default : System.Web.UI.Page
	{
		List<Pergunta> perguntas = new List<Pergunta>();
			
		public void Adicionar(object sender, EventArgs args)
		{			
			Console.Write(sender);
		}
		
		public void MyBtnHandler(object sender,EventArgs args)
		{
			lerXML();
			
			Button btn =(Button)sender;
			
			switch(btn.CommandName)
			{
			case "Somar":
				Console.WriteLine(btn.CommandArgument);
				break;
			case "Subtrair":
				Console.WriteLine(btn.CommandArgument);
				break;
			}
		}
	
		public void lerXML()
		{
			XmlTextReader reader = new XmlTextReader ("/home/italoney/x.xml");
			
			
            while (reader.Read()) 
            {
                switch (reader.NodeType) 
                {
                    case XmlNodeType.Element: // The node is an element.
                        if(reader.Name.Equals("categoria"))
						{
							Console.WriteLine(reader.Name.ToString());
							reader.Read();
							reader.Read();
							Console.WriteLine(reader.Name.ToString());
							if(reader.Name.Equals("perguntas"))
							{
								
								while (reader.Read())
								{
									Pergunta p = null;
									string pergunta = String.Empty;
									string resposta1 = String.Empty;
									string resposta2 = String.Empty;
								    string resposta3 = String.Empty;
									string resposta4 = String.Empty;
									string correta = String.Empty;
								
									if(reader.Name.Equals("pergunta"))
									{
										while (reader.Read())
										{
										
										if(reader.AttributeCount > 0){
											if(reader.GetAttribute("resposta").ToString().Equals("s"))
												correta = reader.ReadString();
										}
										
											switch(reader.Name)
											{
												case "texto":
													pergunta = reader.ReadString();
												break;
											
												case "a":
													resposta1 = reader.ReadString();
												break;
											
												case "b":
													resposta2 = reader.ReadString();
												break;
											
												case "c":
													resposta3 = reader.ReadString();
												break;
											
												case "d":
													resposta4 = reader.ReadString();
													p = new Pergunta(pergunta,resposta1,resposta2,resposta3,resposta4,correta);
													perguntas.Add(p);
											Console.WriteLine(perguntas.Count);
												break;
											}
										
											
										}
											
									}
								}
							}
						}
                        break;
                
            	}
            	Console.ReadLine();
			}
		}
	}
}
			
	